package it.allerj.common.utility;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;



public class DateUtil  {
  public static Date convertStringsToDate(String day, String month, String year){
    Date date = null;
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    try {
      String oldFormat = day+"/"+month+"/"+year;
      date = df.parse(oldFormat);
      String newFormat = df.format(date);
      if(!newFormat.equals(oldFormat))
        return null;
    } catch(Exception e){
      
    }
    //javax.servlet.jsp.tagext.
    return date;
    
  }
  public static String  convertDateToString(Date date) {
    return convertDateToString (date, new SimpleDateFormat("dd.MM.yyyy '-' HH:mm:ss ")); 
  }
  public static String  convertDateToString(Date date, DateFormat dateFormat){
    return dateFormat.format(date);
  }
  
  /**
	 * Converte una java.util.Date in una java.sql.Date.
	 * @param utilDate
	 * @return
	 */
	public static java.sql.Date toSqlDate(java.util.Date utilDate)
	{
		if(utilDate !=null)
			return new java.sql.Date(utilDate.getTime());
		else
			return null;
	}

	/**
	 * Converte una java.util.Date in una java.sql.Date.
	 * @param utilDate
	 * @return
	 */
	public static java.util.Date toUtilDate(java.sql.Date utilDate)
	{
		if(utilDate !=null)
			return new java.util.Date(utilDate.getTime());
		else
			return null;
	}
}